﻿using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using WeBlog.Interfaces;
using WeBlog.Models;
using WeBlog.Repositories;

namespace WeBlog.Widgets {
	[Export(typeof(IWidget))]
    public class TagWidget : IWidget
	{
	    private IUnitOfWork _unitOfWork;
        
        [ImportingConstructor]
        public TagWidget( IUnitOfWork unitOfWork )
        {
            _unitOfWork = unitOfWork;
        }

        public string Name
        {
            get { return "Tags"; }
        }

        public bool IsEditable
        {
            get { return false; }
        }

        public dynamic ViewModel
        {
            get
            {
                var repository = new TagRepository(_unitOfWork);
                return repository.FindUsedTags().AsEnumerable();
            }
        }
    }
}